<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>react 虚拟dom</title>
</head>

<body>
  <div id="app"></div>

  <script src="https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.development.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/@babel/standalone@7.24.5/babel.min.js"></script>
  <script type="text/babel">
    // react 是用来生成虚拟 dom
    // react--dom 是用来将虚拟 dom 转化成真实 dom 的
    const root = ReactDOM.createRoot(document.getElementById('app')) // 创建一个根节
    // root.render('<h1>hello world</h1>') // 这样做是将真实 dom 渲染到页面上，没有意义。react-dom就是将虚拟dom转化成真实 dom 的
    // const vdom = React.createElement('h1', { key: 1 }, ['hello world', React.createElement('span', { key: 2 }, 'react')])
    const { useState, useEffect } = React


    const Count = () => {
      const [count, setCount] = useState(() => {
        console.log('init', 0);
        return 0
      })
      console.log('触发');
      const handleClick = () => {
        setCount(count + 1)
        console.log(count);
      }
      useEffect(() => {
        let i = 0
        while (i < 10000000) {
          i++
        }
        setCount(5)
        return () => {
        }

        return () => {
          console.log('销毁');
        }
      })
      return (
        <div>
          <button id="btn" onClick={handleClick}>count + 1</button>
          <h5>{count}</h5>
        </div>

      )

    }




    const vdom = (
      <div>
        <Count />
      </div>
    )
    root.render(vdom)

  </script>

</body>

</html>